using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using HeThongDAO;
using NUnit.Framework;
using System.Data;

namespace _041346_1041351_1041352_UnitTest
{
    [TestFixture]
    public class TestPhieuThu
    {
        [Test]
        public void ThemPhieuThu1()
        {
            //tao mot datarow de so sanh
            DataTable dt_pt = PhieuThuDAO.DocCauTruc();
            DataRow dr_pt = dt_pt.NewRow();
            dr_pt["MaPhieuThu"] = 11;
            dr_pt["MaKhachHang"] = 1;
            dr_pt["NgayThu"] = "05/28/2011";
            dr_pt["SoTienThu"] = 120000;

            //them mot phieu thu vao csdl
            PhieuThuDTO pt = new PhieuThuDTO();
            pt.IMaKhachHang = 1;
            pt.DateNgayThu = DateTime.ParseExact("28/05/2011", "dd/MM/yyyy", null);
            pt.DSoTienThu = 120000;
            PhieuThuDAO.ThemPhieuThu(pt);

            //lay dong vua them trong csdl
            DataTable dt = PhieuThuDAO.LayDanhSach();
            DataRow dr = dt.Rows[dt.Rows.Count - 1];

            //test so sanh
            Assert.AreEqual(dr_pt["MaPhieuThu"], dr["MaPhieuThu"]);
            Assert.AreEqual(dr_pt["MaKhachHang"], dr["MaKhachHang"]);
            Assert.AreEqual(dr_pt["NgayThu"], dr["NgayThu"]);
            Assert.AreEqual(dr_pt["SoTienThu"], dr["SoTienThu"]);
        }
        [Test]
        public void ThemPhieuThu2()
        {
            //tao mot datarow de so sanh
            DataTable dt_pt = PhieuThuDAO.DocCauTruc();
            DataRow dr_pt = dt_pt.NewRow();
            dr_pt["MaPhieuThu"] = 11;
            dr_pt["MaKhachHang"] = 1;
            dr_pt["NgayThu"] = "05/28/2011";
            dr_pt["SoTienThu"] = 120000;

            //them mot phieu thu vao csdl
            PhieuThuDTO pt = new PhieuThuDTO();
            pt.IMaKhachHang = 1;
            pt.DateNgayThu = DateTime.ParseExact("28/05/2011", "dd/MM/yyyy", null);
            pt.DSoTienThu = 120000;
            PhieuThuDAO.ThemPhieuThu(pt);

            //lay dong vua them trong csdl
            DataTable dt = PhieuThuDAO.LayDanhSach();
            DataRow dr = dt.Rows[dt.Rows.Count - 1];

            //test so sanh
            Assert.LessOrEqual(int.Parse(dr_pt["MaPhieuThu"].ToString()), int.Parse(dr["MaPhieuThu"].ToString()));
            Assert.AreEqual(dr_pt["MaKhachHang"], dr["MaKhachHang"]);
            Assert.AreEqual(dr_pt["NgayThu"], dr["NgayThu"]);
            Assert.AreEqual(dr_pt["SoTienThu"], dr["SoTienThu"]);
        }
    }
}
